package jdbc.way4;



import jdbc.connection.Connection;

import java.util.ArrayList;
import java.util.List;

public class ConnectionFactoryManager {
    private static List<ConnectionFactory> list = new ArrayList<ConnectionFactory>();

    public static Connection getConnection(String url, String username, String password) {
        for (ConnectionFactory factory : list) {
            Connection connection = factory.createConnection(url, username, password);
            if (connection != null) {
                return connection;
            }
        }
        return null;
    }

    public static void register(ConnectionFactory factory) {
        list.add(factory);
    }
}
